// SPDX-License-Identifier: GPL-3.0-or-later

import QtQuick
import QtQuick.Layouts
import Fk.Pages
import Fk.RoomElement

GraphicsBox {
  id: root
  property int min
  property int max
  property string prompt
  property string question
  property string ansa
  property string ansb
  property string ansc
  property string ansd
  property var cancelsign: []

  title.text: Backend.translate(prompt !== "" ? processPrompt(prompt) : "$Choice")
  width: 400
  height: 200
  
  function processPrompt(prompt) {
    const data = prompt.split(":");
    let raw = Backend.translate(data[0]);
    const src = parseInt(data[1]);
    const dest = parseInt(data[2]);
    if (raw.match("%src")) raw = raw.replace(/%src/g, Backend.translate(getPhoto(src).general));
    if (raw.match("%dest")) raw = raw.replace(/%dest/g, Backend.translate(getPhoto(dest).general));
    if (raw.match("%arg2")) raw = raw.replace(/%arg2/g, Backend.translate(data[4]));
    if (raw.match("%arg")) raw = raw.replace(/%arg/g, Backend.translate(data[3]));
    return raw;
  }

  ColumnLayout {
    anchors.fill: parent
    anchors.topMargin: 20
    anchors.leftMargin: 20
    anchors.rightMargin: 20
    anchors.bottomMargin: 20

     Row {
      Layout.alignment: Qt.AlignHCenter
      spacing: 20
      MetroButton {
        Layout.alignment: Qt.AlignHCenter
        id:  answera
       text:Backend.translate(ansa)
        textFont.pixelSize: 12
        width: 80
        height:40

        onClicked: {
          close();
          roomScene.state = "notactive";
          ClientInstance.replyToServer("", JSON.stringify(ansa));
        }
      }

      MetroButton {
        Layout.alignment: Qt.AlignHCenter
        id: answerb
       text:Backend.translate(ansb)
        textFont.pixelSize: 12

        width: 80
        height: 40

        onClicked: {
          close();
           ClientInstance.replyToServer("", JSON.stringify(ansb));
        }
      }
     }
     
     Row {
       Layout.alignment: Qt.AlignHCenter
        spacing: 20
      MetroButton {
        Layout.alignment: Qt.AlignHCenter
        id:  answerc
        text:Backend.translate(ansc)
        textFont.pixelSize: 12
        width: 80
        height: 40

        onClicked: {
          close();
          roomScene.state = "notactive";
          ClientInstance.replyToServer("", JSON.stringify(ansc));
        }
      }

      MetroButton {
        Layout.alignment: Qt.AlignHCenter
        id:  answerd
       text:Backend.translate(ansd)
        textFont.pixelSize: 12
        width: 80
        height: 40

        onClicked: {
          close();
          roomScene.state = "notactive";
          ClientInstance.replyToServer("", JSON.stringify(ansd));
        }
      }

    }


  }



  function loadData(data) {
    const d = data;
    const b=data[0];
    ansa=b[0];
    ansb=b[1];
    ansc=b[2];
    ansd=b[3];
    prompt = d[1];
  
  }
}

